home *** CD-ROM | disk | FTP | other *** search
- Path: news.itg.ti.com!usenet
- From: dwnw%mimi@magic.itg.ti.com (Doug Nintzel)
- Newsgroups: comp.lang.c++
- Subject: Allocating memory in windows programs
- Date: 21 Mar 1996 07:30:40 GMT
- Organization: TI(itg/is&s)
- Distribution: world
- Message-ID: <4ir0j0$2ge@dsk92.itg.ti.com>
- NNTP-Posting-Host: ows-14.itg.ti.com
- Mime-Version: 1.0
- Content-Type: Text/Plain; charset=US-ASCII
- X-Newsreader: WinVN 0.99.7
-
- Hello, I am new at windows programming. I am using MS-SDK/c++. I am using the
- below code to allocate memory....
- /****************************************************************************/
- memtst()
- {
- char FAR*str;
- i=0;
-
- /*
- if((str=(char*)malloc(sizev))==NULL){MessageBox(hWnd,"GlobLock()failed","globl
- ock",MB_OK);return(0);}
- for(i=0;i<555;++i)str[i]='x';str[25]='\0';
- */
- if((hmem=GlobalAlloc(GHND,100))==NULL){MessageBox(hWnd,"GlobAlloc(),
- failed",MB_OK);return(0);}
- str=(char FAR*)GlobalLock(hmem);
- if(str==NULL){MessageBox(hWnd,"GlobLock()failed","globlock",MB_OK);return(0);}
- MessageBox(hWnd,str,"ALLOC/LOCK OK",MB_OK);
- strcpy(str,"mem test ok");
- MessageBox(hWnd,str,"str content",MB_OK);
- }
- /****************************************************************************/
- ...it crashes at strcpy(str,"mem test ok");...
-
- I have also tried to used the commented out malloc() test instead of
- GlobalAlloc().
- I have tried several other changes/combinations w/no luck.
- I have also checked c++ FAQ's and checked several book stores.
- I am running out of ideas!!!...Please help.....
-
- Thanks, Doug
-
-